package com.pqc.tbk.web.scheduling;

import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.context.support.WebApplicationContextUtils;

import com.pqc.tbk.service.admin.SystemService;

public class InitSettings implements ServletContextListener {

	private SystemService systemService;
	private static Logger log = LoggerFactory.getLogger(InitSettings.class);

	@Override
	public void contextInitialized(final ServletContextEvent sce) {
		log.debug("系统启动，绑定系统设置");

		final ServletContext application = sce.getServletContext();
		systemService = (SystemService) WebApplicationContextUtils
				.getWebApplicationContext(sce.getServletContext()).getBean(
						"systemServiceImpl");
		try {
			systemService.bindSysProperties();
			application.setAttribute("sysconfig", systemService.convertToMap());
		}
		catch (final Exception e) {
			log.error("系统绑定失败", e);
			e.printStackTrace();
		}
	}

	@Override
	public void contextDestroyed(final ServletContextEvent sce) {
		log.debug("关闭中。。。");
	}

}
